﻿598.区间加法-II
int maxCount(int m, int n, int** ops, int opsSize, int* opsColSize) {
    if (opsSize == 0)
    {
        return m * n;
    }

    int min1 = ops[0][0], min2 = ops[0][1];
    for (int i = 0; i < opsSize; i++)
    {
        if (min1 > ops[i][0])
        {
            min1 = ops[i][0];
        }
        if (min2 > ops[i][1])
        {
            min2 = ops[i][1];
        }

    }
    return min1 * min2;;
}

599.两个列表的最小索引总和
/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
    char** findRestaurant(char** list1, int list1Size, char** list2, int list2Size, int* returnSize) {
    int* arr = (int*)malloc(sizeof(int) * list1Size);
    char** ans = (char**)malloc(sizeof(char*) * list1Size);
    char** temp1 = (char**)malloc(sizeof(char*) * list1Size);
    *returnSize = 0;

    int count = 0;
    for (int i = 0; i < list1Size; i++)
    {
        for (int j = 0; j < list2Size; j++)
        {
            if (strcmp(list1[i], list2[j]) == 0)
            {
                arr[count] = i + j;
                char* temp = (char*)malloc(sizeof(char) * 31);
                strcpy(temp, list1[i]);
                temp1[count++] = temp;
                break;
            }
        }
    }

    int min = 2000;
    for (int i = 0; i < count; i++)
    {
        if (min > arr[i])
        {
            min = arr[i];
        }
    }

    for (int i = 0; i < count; i++)
    {
        if (arr[i] == min)
        {
            ans[(*returnSize)++] = temp1[i];
        }
    }
    return ans;
}

605.种花问题
bool canPlaceFlowers(int* flowerbed, int flowerbedSize, int n) {
    if (n > (flowerbedSize + 1) / 2)
    {
        return false;
    }
    if (flowerbedSize < 3)
    {
        for (int i = 0; i < flowerbedSize; i++)
        {
            if (flowerbed[i] == 1 && n != 0)
            {
                return false;
            }
        }
        return true;
    }

    int count = 0;
    if (flowerbed[0] == 0 && flowerbed[1] == 0)
    {
        flowerbed[0] = 1;
        count++;
    }
    for (int i = 1; i < flowerbedSize - 1; i++)
    {
        if (flowerbed[i] == 0 && flowerbed[i - 1] == 0 && flowerbed[i + 1] == 0)
        {
            flowerbed[i] = 1;
            count++;
        }
    }
    if (flowerbed[flowerbedSize - 2] == 0 && flowerbed[flowerbedSize - 1] == 0)
    {
        flowerbed[flowerbedSize - 1] = 1;
        count++;
    }

    if (count >= n)
    {
        return true;
    }
    else
    {
        return false;
    }
}

628.三个数的最大乘积
int maximumProduct(int* nums, int numsSize) {
    int fir = -1000, sec = -1000, thi = -1000, min1 = 1000, min2 = 1000;
    for (int i = 0; i < numsSize; i++)
    {
        if (nums[i] > fir)
        {
            thi = sec;
            sec = fir;
            fir = nums[i];
        }
        else if (nums[i] > sec && nums[i] <= fir)
        {
            thi = sec;
            sec = nums[i];
        }
        else if (nums[i] > thi && nums[i] <= sec)
        {
            thi = nums[i];
        }

        if (nums[i] <= min1)
        {
            min2 = min1;
            min1 = nums[i];
        }
        else if (nums[i] <= min2 && nums[i] > min1)
        {
            min2 = nums[i];
        }
    }
    return thi * sec * fir > fir * min1 * min2 ? thi * sec * fir : fir * min1 * min2;
}

643.子数组最大平均数-I
double findMaxAverage(int* nums, int numsSize, int k) {
    double sum = 0, ans = 0;
    for (int i = 0; i < k; i++)
    {
        sum += nums[i];
    }
    ans = sum / k;
    for (int i = k; i < numsSize; i++)
    {
        sum += nums[i];
        sum -= nums[i - k];
        if (sum / k > ans)
        {
            ans = sum / k;
        }
    }
    return ans;
}